package com.qzimp.fujiancuo.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVo {

    /**
     * 状态码
     */
    private int code;
    /**
     * 状态信息
     */
    private  String msg;
    /**
     * 返回数据
     */
    private Object data;
    /**
     * 是否成功
     */
    private  boolean success;


    // 默认返回成功状态码，数据对象
    public ResultVo(Object data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.success=true;
        this.data = data;
    }
    // 返回指定状态码，数据对象
    public ResultVo(StatusCode statusCode, Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.success=true;
        this.data = data;
    }

    // 只返回状态码
    public ResultVo(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.success=true;
        this.data = null;

    }

    public  static  ResultVo error(StatusCode statusCode){
        return  new ResultVo(statusCode.getCode(),statusCode.getMsg(),null,false);
    }
    public  static  ResultVo error(StatusCode statusCode,Object data){
        return  new ResultVo(statusCode.getCode(),statusCode.getMsg(),data,false);
    }


}
